﻿Public Class clsDB
    ''' <summary>
    ''' 得到当前表里的数据
    ''' </summary>
    ''' <param name="_workshop">车间</param>
    ''' <param name="_current_section">工段</param>
    ''' <returns>当前表DataTable</returns>
    Public Function getCurrentData(_workshop As Integer, _current_section As String) As DataTable
        Dim dt As New DataTable
        Dim szSql As String = ""
        szSql = "SELECT * FROM sf.b_workshop_current "
        szSql &= " WHERE factory_id = ? and workshop = ? and current_section = ?"
        dt = DBacs.ExecuteSql(szSql, -1, g_factory_id, g_cj_yzz, _current_section)

        Return dt
    End Function

    ''' <summary>
    ''' 得到支座型号信息
    ''' </summary>
    ''' <param name="_prod_spec_id">支座型号的物料编码</param>
    ''' <returns>支座型号信息Datatable</returns>
    Public Function getProdSpec(_prod_spec_id As String) As DataTable
        Dim dt As New DataTable
        Dim szSql As String = ""
        szSql = "SELECT * FROM sf.t_prod_spec "
        szSql &= " WHERE factory_id = ? and prod_spec_id = ? "
        dt = DBacs.ExecuteSql(szSql, -1, g_factory_id, _prod_spec_id)

        Return dt
    End Function

    ''' <summary>
    ''' 得到FLB主档信息
    ''' </summary>
    ''' <param name="_flb_material_code">法兰板物料编码</param>
    ''' <returns>法兰板物料DataTable</returns>
    Public Function getFLBSpecInfo(_flb_material_code As String) As DataTable
        Dim dt As New DataTable
        Dim szSql As String = ""
        szSql = "SELECT * FROM sf.t_mst_flb "
        szSql &= " WHERE material_code = ? "
        dt = DBacs.ExecuteSql(szSql, -1, _flb_material_code)

        Return dt
    End Function

    ''' <summary>
    ''' 得到GJB主档信息
    ''' </summary>
    ''' <param name="_GJB_material_code">骨架板物料编码</param>
    ''' <returns>骨架板物料DataTable</returns>
    Public Function getGJBSpecInfo(_GJB_material_code As String) As DataTable
        Dim dt As New DataTable
        Dim szSql As String = ""
        szSql = "SELECT * FROM sf.t_mst_gjb "
        szSql &= " WHERE material_code = ? "
        dt = DBacs.ExecuteSql(szSql, -1, _GJB_material_code)

        Return dt
    End Function

    ''' <summary>
    ''' 得到预装芯座所用的骨架板类型 和 一车间6工位的设定是否相同的判断结果
    ''' </summary>
    ''' <returns>0：不同，1：相同，-1：辊涂计划内容不全，-2：预组装计划内容不全</returns>
    Public Function Equals_GJB2_YZZ() As Integer
        Dim strSQL As String = ""

        strSQL &= " select b.gjb_material_code material_code  ,c.mst_value gjb_type"
        strSQL &= " from sf.b_workshop_current a inner join sf.t_prod_spec b "
        strSQL &= " On a.support_model=b.prod_spec_id "
        strSQL &= " inner join sf.t_mst_gjb c on c.material_code=b.gjb_material_code  "
        strSQL &= "where a.workshop=? and a.current_section=?"
        Dim dtGJBZP As DataTable = DBacs.ExecuteSql(strSQL, -1, g_cj_pt, g_ws_pt_gjbzp)

        If dtGJBZP.Rows.Count > 0 AndAlso DBNULLtoBlank(dtGJBZP.Rows(0)("material_code")) <> "" Then
        Else
            'lblPlan.Text = "辊涂计划内容不全"
            Return -1
        End If

        strSQL = ""
        strSQL &= " select b.gjb_material_code material_code ,c.mst_value gjb_type"
        strSQL &= " from sf.b_workshop_current a inner join sf.t_prod_spec b "
        strSQL &= " On a.support_model=b.prod_spec_id "
        strSQL &= " inner join sf.t_mst_gjb c on c.material_code=b.gjb_material_code  "
        strSQL &= " where  a.workshop=? and current_section=?"
        Dim dtYZZ As DataTable = DBacs.ExecuteSql(strSQL, -1, g_cj_yzz, "YZZ")
        If dtYZZ.Rows.Count > 0 AndAlso DBNULLtoBlank(dtYZZ.Rows(0)("material_code")) <> "" Then
        Else
            'lblPlan.Text = "预组装计划内容不全"
            Return -2
        End If

        If dtGJBZP.Rows(0)("material_code") = dtYZZ.Rows(0)("material_code") Then
            'lblPlan.Text = String.Format("计划相同：一车间：{0}({1}) 二车间：{2}({3}) ", dtGJBZP.Rows(0)("gjb_type"), dtGJBZP.Rows(0)("material_code"), dtYZZ.Rows(0)("gjb_type"), dtYZZ.Rows(0)("material_code"))

            'lblPlan.ForeColor = Color.DarkGreen
            Return 1
        Else
            'lblPlan.Text = String.Format("计划不同：一车间：{0}({1}) 二车间：{2}({3}) ", dtGJBZP.Rows(0)("gjb_type"), dtGJBZP.Rows(0)("material_code"), dtYZZ.Rows(0)("gjb_type"), dtYZZ.Rows(0)("material_code"))
            'lblPlan.ForeColor = Color.Red
            Return 0
        End If

    End Function
End Class
